package cn.dvptech.remotemate.screenmirror.server;

import android.util.Log;

import java.util.concurrent.ArrayBlockingQueue;

import cn.dvptech.remotemate.screenmirror.screenHelper.Frame;
import timber.log.Timber;

/**
 *    author  : ulongx
 *    website : www.dvptech.cn
 *    date    : 2024/7/21
 *    desc    :
 */
public class NormalPlayQueue {
    private ArrayBlockingQueue<Frame> mPlayQueue;
    private final String TAG = "NormalPlayQueue";
    private static final int NORMAL_FRAME_BUFFER_SIZE = 800; //缓存区大小

    public NormalPlayQueue() {
        mPlayQueue = new ArrayBlockingQueue<Frame>(NORMAL_FRAME_BUFFER_SIZE, true);
    }


    public Frame takeByte() {
        try {
            if (mPlayQueue.size() >= NORMAL_FRAME_BUFFER_SIZE) {
                Timber.tag(TAG).e("too much frame in NormalPlayQueue %s", mPlayQueue.size());
            }
            return mPlayQueue.take();
        } catch (InterruptedException e) {
            Timber.tag(TAG).e("take bytes exception%s", e.toString());
            return null;
        }
    }

    public void putByte(Frame frame) {
        try {
            mPlayQueue.put(frame);
        } catch (InterruptedException e) {
            Timber.tag(TAG).e("put bytes exception%s", e.toString());
        }
    }

    public void stop() {
        if (mPlayQueue != null) {
            mPlayQueue.clear();
        }
    }

}
